package com.chen.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;

/**
 * @Author:chenao
 * @DATE:2022/3/12 16:50
 */

public class DateUtils {

    /**
     * 将传统字符串形式转换为以下格式
     * @param originTime
     * @return
     */
    public static String formatDateString(String originTime){
        String formatPattern="yyyy-MM-dd HH:mm:ss";
        if (originTime.contains("GMT")){
            Date date = new Date(originTime);
            return DateUtil.format(date, formatPattern);
        }else {
            return originTime;
        }
    }

    /**
     * 将格式转换回去
     * @param originTime
     * @return
     */
    public static String parseDateString(String originTime){
        String formatPattern="yyyy-MM-dd HH:mm:ss";
        DateTime parse = DateUtil.parse(originTime, formatPattern);
        return parse.toString();
    }
}
